package com.tarena.demo.luban.all.main.config;

import cn.tedu.luban.demo.cart.api.CartApi;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


public class ProxyConfiguration {
    @Bean
    public CartApi getProxy(){
        //1. 同样要启动一个dobbo的进程
        DubboBootstrap client=DubboBootstrap.getInstance();
        //2. 提供一个名称
        client.application("order-consumer");
        //3. protocol
        //ProtocolConfig protocolConfig=new ProtocolConfig("dubbo",-1);
        //client.protocol(protocolConfig);
        //4. 注册中心
        RegistryConfig registryConfig=new RegistryConfig("nacos://localhost:8848");
        client.registry(registryConfig);
        //5. 告诉dubbo进程，我想要调用谁 CartApi
        ReferenceConfig<CartApi> referenceConfig=new ReferenceConfig<CartApi>();
        referenceConfig.setInterface(CartApi.class);
        client.reference(referenceConfig);
        //6. 获取一个代理使用
        CartApi cartApiProxy = referenceConfig.get();
        System.out.println("拿到代理类："+cartApiProxy.getClass().getName());
        return cartApiProxy;
    }

}
